<template>
  <BaseBreadcrumb :title="page.title" :breadcrumbs="breadcrumbs"></BaseBreadcrumb>
  <UiParentCard>
    <v-row>
      <v-col cols="12" lg="3" md="4" sm="6">
        <v-text-field
          v-model="searchData.userKey"
          label="请输入用户标识"
          hide-details
          clearable
          @keyup.enter="doQueryFirstPage"
          @click:clear="doQueryFirstPage"
        ></v-text-field>
      </v-col>
      <v-col cols="12" lg="3" md="4" sm="6">
        <v-text-field
          v-model="searchData.userType"
          label="请输入用户类型"
          hide-details
          clearable
          @keyup.enter="doQueryFirstPage"
          @click:clear="doQueryFirstPage"
        ></v-text-field>
      </v-col>
      <v-col cols="12" lg="3" md="4" sm="6">
        <v-text-field
          v-model="searchData.userRegion"
          label="请输入用户渠道"
          hide-details
          clearable
          @keyup.enter="doQueryFirstPage"
          @click:clear="doQueryFirstPage"
        ></v-text-field>
      </v-col>
      <v-col cols="12">
        <TableWithPager @query="doTableQuery" ref="tableWithPagerRef" :infos="tableInfos">
          <el-table-column label="输入图像" min-width="150px">
            <template #default="{ row }">
              <v-avatar size="80" rounded="md">
                <img :src="row.inputS3Url" alt="输入图像" height="80" />
              </v-avatar>
            </template>
          </el-table-column>
          <el-table-column label="输出图像" min-width="150px">
            <template #default="{ row }">
              <v-avatar size="80" rounded="md">
                <img :src="row.outS3Url" alt="输出图像" height="80" />
              </v-avatar>
            </template>
          </el-table-column>
          <el-table-column label="比分" min-width="100px">
            <template #default="{ row }">
              {{ row.dist.toFixed(4) }}
            </template>
          </el-table-column>
          <el-table-column label="用户标识" min-width="100px" show-overflow-tooltip>
            <template #default="{ row }">
              <template v-if="row.userKey">
                {{ row.userKey }}
              </template>
              <template v-else> 未指定 </template>
            </template>
          </el-table-column>
          <el-table-column label="用户类型" prop="userType" min-width="100px" show-overflow-tooltip></el-table-column>
          <el-table-column label="用户渠道" prop="userRegion" min-width="100px" show-overflow-tooltip></el-table-column>
          <el-table-column label="py耗时" prop="durationPy" min-width="90px">
            <template #default="{ row }">
              {{ row.durationPy.toFixed(4) }}
            </template>
          </el-table-column>
          <el-table-column label="接口耗时" prop="duration" min-width="90px">
            <template #default="{ row }">
              {{ row.duration.toFixed(4) }}
            </template>
          </el-table-column>
          <el-table-column label="响应内容" prop="note" min-width="200px" show-overflow-tooltip></el-table-column>
          <el-table-column label="创建时间" min-width="165px">
            <template #default="{ row }">
              {{ format.dateFormat(row.createdAt, "YYYY-MM-DD HH:mm:ss") }}
            </template>
          </el-table-column>
        </TableWithPager>
      </v-col>
    </v-row>
  </UiParentCard>
</template>
<script setup lang="ts">
import { reactive, ref, onMounted } from "vue";
import BaseBreadcrumb from "@/components/shared/BaseBreadcrumb.vue";
import UiParentCard from "@/components/shared/UiParentCard.vue";

import { http, format } from "@/utils";

const page = ref({ title: "人脸查询日志" });
const breadcrumbs = ref([
  {
    text: "人脸服务",
    disabled: false,
    href: "#"
  },
  {
    text: "人脸查询日志",
    disabled: true,
    href: "#"
  }
]);
const searchData = reactive({
  userKey: "",
  userType: "",
  userRegion: ""
});
const tableInfos = reactive({
  list: [],
  total: 0
});
const tableWithPagerRef = ref();

const doTableQuery = async (options = {}) => {
  const [err, res] = await http.get({
    url: "/esrgan/face/search/log",
    showLoading: tableWithPagerRef.value.el,
    data: {
      ...searchData,
      ...options
    }
  });
  if (res) {
    tableInfos.list = res.list || [];
    tableInfos.total = res.total;
  } else {
    tableInfos.list = [];
    tableInfos.total = 0;
  }
};

const doQueryFirstPage = () => {
  tableWithPagerRef.value.query({ page: 1 });
};

onMounted(() => {
  doTableQuery();
});
</script>
